﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LinearRegression.models
{
    /// <summary>
    /// 新建一个线性回归分析的类
    /// </summary>
    public class LeastSquare
    {
        public static double Getb(double[] x, double[] y, double avex, double avey)
        {
            double numerator = 0;
            double denominator = 0;
            double b = 0;
            for (int i = 0; i < x.Length; i++)
            {
                numerator += (x[i] - avex) * (y[i] - avey);
                denominator += Math.Pow((x[i] - avex), 2);
                b = numerator / denominator;
            }
            return b;
        }
        public static double Geta(double avex, double avey, double b)
        {
            double a = avey - avex * b;
            return a;
        }

    }
}
